package miage.ecom.commandes;


import java.io.PrintStream;
import java.util.StringTokenizer;
import miage.ecom.Shell.ShellContext;

    


public class EchoCommandImpl implements ShellCommand
    {
    private ShellContext context = null;
    public EchoCommandImpl(ShellContext context)
    {
    this.context = context;
    }
    /**
    * renvoie le nom de la commande
    * @return
    */
    @Override
    public String getName()
    {
    return "echo";
    }
    /**
    * renvoie le nom de la commande
    * @return
    */
    @Override
    public String getUsage()
    {
    return "echo <messages>";
    }
    /**
    * renvoie la description de la commande
    * @return
    */
    @Override
    public String getShortDescription()
    {
    return "echo messages.";
    }
    /**
    * execute la commande
    * @param cmdline
    * @param out
    * @param err
    */
    @Override
    public void execute(String cmdline, PrintStream out, PrintStream err)
    {
    StringTokenizer st = new StringTokenizer(cmdline, " ");
    // Ignore the command name.
    st.nextToken();
    // There should be at least one string.
    if (st.countTokens() >= 0)
    {
    while (st.hasMoreTokens())
    {
    out.print(st.nextToken().trim());
    out.print(' ');
    }
    out.println();
    }
    else
    {
    err.println("Incorrect number of arguments");
    }
    }
    } 